/*
 * @Author: WangLi
 * @Date: 2024-03-19 06:04:49
 * @LastEditors: WangLi
 * @LastEditTime: 2024-05-10 19:15:40
 */
import WPage from "../../common/WPage";
import { getUuid, writeBLECharacteristicValue } from "../../utils/common";

const app = getApp();
WPage({
  data: {
    title: "设备信息",
    deviceName: "",
    isDeviceInfoShow: false,
  },
  onLoad(options) {},
  async handleEditDeviceName() {
    const dialog = this.selectComponent("#s-dialog");
    const _this = this;
    try {
      await dialog.confirm({
        title: "修改设备名称",
        // 需要异步处理，使用beforeClose,不需要则删掉
        beforeClose: (action) =>
          new Promise((resolve) => {
            if (_this.data.deviceName) {
              resolve(true);
            } else {
              wx.showToast({
                title: "设备名称不能为空",
                icon: "none",
              });
              resolve(false);
            }
          }),
      });
      console.log("confirm");
      this.handleSave();
    } catch (error) {
      console.log("cancel");
    }
  },
  handleSave() {
    const serviceId = getUuid("5505");
    writeBLECharacteristicValue(serviceId, getUuid("0050"), this.data.deviceName, "设备名称修改");
  },
  handleGetDeviceInfo() {
    this.setData({
      isDeviceInfoShow: !this.data.isDeviceInfoShow,
    });
  },
  handleSaveDeviceInfo() {},
});
